/*
 * @Copyright: Citylife 2021
* @Author: shaokui.gu
 * @Date: 2021-02-19 15:02:20
 * @Description: 
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_scaffold_plugin/pages/students/students_page.dart';
import 'package:flutter_scaffold_plugin/pages/teacher/teacher_living_page.dart';

import '../../base/base.dart';
import '../../base/base_page.dart';
import '../../utils/locale/local_manager.dart';
import '../mine/mine_page.dart';

class MainController extends TemplateController
    with SingleGetTickerProviderMixin {
  TabController tabController;

  final _tabIndex = 0.obs;
  get tabIndex => this._tabIndex.value;
  set tabIndex(value) => this._tabIndex.value = value;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    tabController = TabController(
      initialIndex: 0,
      length: 2,
      vsync: this,
    );
    tabController.addListener(() {
      tabIndex = tabController.index;
    });
  }
}

class MainPage extends TemplatePage<MainController> {
  @override
  Widget buildBody(BuildContext context) {
    return TabBarView(
      controller: controller.tabController,
      physics: NeverScrollableScrollPhysics(),
      children: [
        TeacherLivingPage(),
        StudentPage(),
        // MinePage(),
      ],
    );
  }

  @override
  Widget buildBottomBar(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Obx(() => BottomNavigationBar(
            backgroundColor: theme.colors.tabBarBackgroundColor,
            currentIndex: controller.tabIndex,
            selectedItemColor: theme.colors.tabItemTitleSelectedColor,
            unselectedItemColor: theme.colors.tabItemTitleNormalColor,
            selectedFontSize: 10.0.sp,
            unselectedFontSize: 10.0.sp,
            items: [
              BottomNavigationBarItem(
                label: appString.laoshi,
                icon: Icon(
                  CupertinoIcons.home,
                  color: theme.colors.tabItemNormalIconColor,
                ),
                activeIcon: Icon(
                  CupertinoIcons.home,
                  color: theme.colors.tabItemSelectedIconColor,
                ),
              ),
              BottomNavigationBarItem(
                label: appString.xuesheng,
                icon: Icon(
                  CupertinoIcons.home,
                  color: theme.colors.tabItemNormalIconColor,
                ),
                activeIcon: Icon(
                  CupertinoIcons.home,
                  color: theme.colors.tabItemSelectedIconColor,
                ),
              ),
              // BottomNavigationBarItem(
              //   label: appString.xuesheng,
              //   icon: Icon(
              //     CupertinoIcons.person,
              //     color: theme.colors.tabItemNormalIconColor,
              //   ),
              //   activeIcon: Icon(
              //     CupertinoIcons.person,
              //     color: theme.colors.tabItemSelectedIconColor,
              //   ),
              // ),
            ],
            onTap: (index) {
              controller.tabController.index = index;
            },
          )),
    );
  }

  @override
  Widget buildNavigationBar(BuildContext context) {
    return null;
  }

  @override
  MainController initController() {
    return MainController();
  }
}
